package com.ztgf.sys.api.client;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import com.ztgf.sys.models.service.ISysUserRoleRelationService;
import com.ztgf.sys.models.bo.SysUserRoleRelationBO;
import com.ztgf.sys.models.dto.SysUserRoleRelationDTO;

/**
 * 用户角色关系表控制器
 *
 * @author YUE
 * @Date 2020-05-27 17:39:19
 */

@RestController
@RequestMapping("/api/sysUserRoleRelation")
@Slf4j
@Api(value = "SysUserRoleRelationApiController",tags = "用户角色关系表Api接口")
public class SysUserRoleRelationApiController {

    @DubboReference
    private ISysUserRoleRelationService sysUserRoleRelationService;

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<SysUserRoleRelationDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        SysUserRoleRelationDTO dto = sysUserRoleRelationService.selectById(id);

        return new Result<>(dto);
    }

    @ApiOperation(value = "用户角色关系表列表",notes = "用户角色关系表列表")
    @PostMapping("/queryPageList")
    public Result<Page<SysUserRoleRelationDTO>> queryPageList(SysUserRoleRelationBO bo){
       Wrapper<SysUserRoleRelationDTO> wrapper = new EntityWrapper<>();
        Page<SysUserRoleRelationDTO> page = new Page<>(bo.getPageNo(), bo.getPageSize());
        page = sysUserRoleRelationService.selectPage(page, wrapper);

        return new Result<>(page);
    }
}
